using System;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

namespace DesktopWidgetApp.Server.Models
{
    /// <summary>
    /// 用户实体
    /// </summary>
    public class User
    {
        /// <summary>
        /// 构造函数，初始化所有必需的属性
        /// </summary>
        public User()
        {
            Id = Guid.NewGuid();
            RegisteredAt = DateTime.UtcNow;
            Statuses = new List<ServerStatus>();
        }

        /// <summary>
        /// 用户ID
        /// </summary>
        [Key]
        public Guid Id { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        [Required]
        [MaxLength(50)]
        public string Username { get; set; } = string.Empty;

        /// <summary>
        /// 邮箱
        /// </summary>
        [Required]
        [EmailAddress]
        [MaxLength(100)]
        public string Email { get; set; } = string.Empty;

        /// <summary>
        /// 密码哈希
        /// </summary>
        [Required]
        public string PasswordHash { get; set; } = string.Empty;

        /// <summary>
        /// 密码盐
        /// </summary>
        [Required]
        public string PasswordSalt { get; set; } = string.Empty;

        /// <summary>
        /// 注册时间
        /// </summary>
        [Required]
        public DateTime RegisteredAt { get; set; }

        /// <summary>
        /// 最后登录时间
        /// </summary>
        public DateTime? LastLoginAt { get; set; }

        /// <summary>
        /// 用户角色
        /// </summary>
        [Required]
        public string Role { get; set; } = "User";

        /// <summary>
        /// 用户状态是否激活
        /// </summary>
        public bool IsActive { get; set; } = true;

        /// <summary>
        /// 登录失败次数
        /// </summary>
        public int AccessFailedCount { get; set; } = 0;
        
        /// <summary>
        /// 账户是否被锁定
        /// </summary>
        public bool IsLocked { get; set; } = false;
        
        /// <summary>
        /// 锁定结束时间
        /// </summary>
        public DateTime? LockoutEnd { get; set; }
        
        /// <summary>
        /// 刷新令牌
        /// </summary>
        public string RefreshToken { get; set; } = string.Empty;
        
        /// <summary>
        /// 刷新令牌过期时间
        /// </summary>
        public DateTime RefreshTokenExpiryTime { get; set; }
        
        /// <summary>
        /// 用户状态记录
        /// </summary>
        public ICollection<ServerStatus> Statuses { get; set; }
    }
}